<template>
  <page-main class="page-appointment-list">
    <div class="p-t-15"></div>
    <current-patient ref="currentPatient" @select="changePatient" />
    <div class="condition">
      <date-select ref="dateSelect" @confirm="changeDate" />
    </div>
    <van-empty description="暂无记录" v-if="list_data.list.length == 0" />
    <van-pull-refresh v-else v-model="list_data.refreshing" @refresh="getList('refresh')">
      <van-empty description="暂时没有数据哦" v-if="list_data.list.length == 0"/>
      <van-list
        v-else
          v-model="list_data.loading"
          :finished="list_data.finished"
          finished-text="没有更多了"
          @load="getList('more')"
      >
        <div class="fly-panel" v-for="(item,index) in list_data.list" :key="index" @click="$util.gotoPage('/appointment/detail',{makeId: item.makeId, from:'list'})">
          <div class="hd">
            <div class="title">{{item.officeName + ' ' +item.makeStaffName}}</div>
            <div class="value">
              <span v-if="item.payStatus == 0 && item.makeStatus == 0" class="c-yellow">待付款</span>
              <span v-else :class="'status status-' + item.makeStatus">{{ $util.setName(item.makeStatus, init_data.makeStatus_list) }}</span>
            </div>
          </div>
          <div class="info">
            <fly-info label="就诊科室" :value="item.officeName"/>
            <fly-info label="医生" :value="item.makeStaffName"/>
            <fly-info label="就诊时间" :value="item.schedulingYearTime"/>
            <fly-info label="就诊人" :value="item.custName"/>
          </div>
        </div>
      </van-list>
    </van-pull-refresh>
    <van-popup v-model="date.show" position="bottom" >
      <van-datetime-picker
        v-model="date.currentDate"
        type="date"
        title="请选择"
        :min-date="date.minDate"
        :max-date="date.maxDate"
        @cancel="date.show = false"
        @confirm="getDate"
      />
    </van-popup>
  </page-main>
</template>
<script>
import currentPatient from '@/view/components/currentPatient';
import dateSelect from '@/view/components/dateSelect';
import flyInfo from '@/components/FlyInfo';
import longList from '@/assets/mixins/longList';
import moment from 'moment';
export default {
  mixins: [longList],
  components:{
    flyInfo,
    currentPatient,
    dateSelect
  },
  data(){
    return {
      list_api: '/admin/registrationApi/page',
      fixed_form:{
        startDate: null,
        endDate: null,
      },
      date:{
        show: false,
        type: null,
        minDate: new Date(2020, 0, 1),
        maxDate: new Date(2025, 10, 1),
        currentDate: new Date(),
      },
      init_data:{},
    }
  },
  created(){
    this.getInitData();
  },
  async mounted(){
    let patient = this.$refs.currentPatient.getCurrentPatient();
    this.fixed_form.patientId = patient.patientId;
    this.getYear();
  },
  methods:{
    async getInitData(){
      this.init_data.makeStatus_list = await this.$util.getDictList('make_status');
      // this.init_data.professional_list = await this.$util.getDictList('professional_title');
    },
    getDate(value){
      this.fixed_form.startDate = moment(value).format('YYYY-MM-DD');
      this.fixed_form.endDate = moment().format('YYYY-MM-DD');
      this.getList('refresh');
      this.date.show = false;
    },
    getYear(){
      this.fixed_form.startDate = moment().subtract(1,'year').format('YYYY-MM-DD');
      this.fixed_form.endDate = moment().format('YYYY-MM-DD');
      this.getList('refresh');
    },
    changeDate(obj){
      console.log(obj);
      this.fixed_form.startDate = obj.start;
      this.fixed_form.endDate = obj.end;
      this.getList('refresh');
    },
    changePatient(obj){
      this.fixed_form.patientId = obj.patientId;
      this.getList('refresh')
    }
  }
}
</script>